import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.StringTokenizer;


class P755_39643 {

//	A, B, and C map to 2
//
//	D, E, and F map to 3
//
//	G, H, and I map to 4
//
//	J, K, and L map to 5
//
//	M, N, and O map to 6
//
//	P, R, and S map to 7
//
//	T, U, and V map to 8
//
//	W, X, and Y map to 9 
	
	static int[] array = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9};
	
	public static void main(String[] args) {
		
		
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			HashMap<String, Integer> map = new HashMap<String, Integer>();
			LinkedList<String> phones = new LinkedList<String>();
			
			readLn();
			
			int numbers = Integer.parseInt(readLn());
			
			for (int j = 0; j < numbers; j++) {
				String line = readLn();
				StringBuilder sb = new StringBuilder();
//				System.out.println(line);
				for (int i = 0; i < line.length(); i++) {
//					System.out.println("> " + line.charAt(i) + - 'A');
					char c = line.charAt(i);
					if (c >= 'A' && c <= 'Z')
						sb.append(array[line.charAt(i) - 'A']);
					else sb.append(c);
				}
				
//				System.out.println("> " + sb);
				
				Integer ocurrence = map.get(sb.toString());
				if (ocurrence == null) {
					ocurrence = Integer.valueOf(0);
				} else {
					if (ocurrence.intValue() == 1) {
						phones.add(sb.toString());
					}
				}
				
				map.put(sb.toString(), Integer.valueOf(ocurrence.intValue() + 1));
				
				
			}
			
			
			
			
			
//			for (Map.Entry<String, Integer> entry : map.entrySet()) {
//				if (entry.getValue() > 1) {
//					phones.add(entry.getKey() + "," + entry.getValue());
//				}
//			}
			
//System.out.println(phones);
			
			if (phones.size() == 0) {
				System.out.println("No duplicates.");
			} else {
				Collections.sort(phones);
				
				StringBuilder sb = new StringBuilder();
				for (String phone : phones) {
//					StringTokenizer st = new StringTokenizer(phone, ",");
//					String p1 = st.nextToken();
					
					sb.append(phone.charAt(0)).append(phone.charAt(1)).append(phone.charAt(2)).append("-").append( 
							phone.charAt(3)).append(phone.charAt(4)).append(phone.charAt(5)).append(phone.charAt(6)).append(" ").append(map.get(phone)).append("\n");

				}
				
				System.out.print(sb.toString());
				
			}

			
			if (k + 1 != cases) System.out.println();
		}
		
		
	}
	
	
	
	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuilder buffer = new StringBuilder();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                if ((car >= 'A' && car <= 'Z') || (car >= '0' && car <= '9') )
                	buffer.append((char) car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
                System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) {
            return (null);
        }
        if ((car < 0) && (buffer.length() == 0))
            return (null);
        return (buffer.toString()).trim();
    }
	
}
